#include "FPCH.h"

#include "FTextLine.h"

namespace Font
{

	TextLine::TextLine(Library* a_Library, Text* a_Text)
	{
		m_Library = a_Library;
		m_Text = a_Text;

		m_DisplayCurrent = NULL;

		m_CharacterCurrent = NULL;
		NextCharacter();
	}
	
	TextLine::~TextLine()
	{
		for (std::vector<TextCharacter*>::iterator it = m_Characters.begin(); it != m_Characters.end();)
		{
			delete *it;
			it = m_Characters.erase(it);
		}
	}

	void TextLine::SetTextDisplay(TextDisplay* a_Display)
	{
		m_DisplayCurrent = a_Display;
		m_CharacterCurrent->display = m_DisplayCurrent;
	}

	void TextLine::AddCharacterPosition(const tb::Vec2& a_Position)
	{
		m_CharacterCurrent->position[m_CharacterCurrent->filled] = a_Position;
	}

	void TextLine::AddCharacterTexCoord(const tb::Vec2& a_TexCoord)
	{
		m_CharacterCurrent->texcoord[m_CharacterCurrent->filled] = a_TexCoord;
	}

	void TextLine::NextCharacterCorner()
	{
		m_CharacterCurrent->filled++;
	}

	void TextLine::NextCharacter()
	{
		if (m_CharacterCurrent)
		{
			m_Characters.push_back(m_CharacterCurrent);
		}

		m_CharacterCurrent = new TextCharacter;
		m_CharacterCurrent->display = m_DisplayCurrent;
		m_CharacterCurrent->filled = 0;
	}

}; // namespace Font